<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/add.css"/>
</head>
<body>
<div id="app">
    <div class="header">
        <span>修改快递信息</span>
    </div>
    <div class="content">
        <table>
            <tr>
                <td class="text-right">运单号</td><td class="content_right"><input class="input inline-input" id="number" placeholder="请输入运单号码"> <span class="btn btn-info" id="find">立即查找</span></td>
            </tr>
        </table>
    </div>


    <div class="header">
        <span>查找信息如下</span>
    </div>
    <div class="content">
        <table>
            <tr>
                <td class="text-right">快递单号</td><td class="content_right"><input class="input" placeholder="请输入快递单号"></td>
            </tr>
            <tr>
                <td class="text-right">快递公司</td><td class="content_right"><input class="input" placeholder="请输入快递公司"></td>
            </tr>
            <tr>
                <td class="text-right">收货人姓名</td><td class="content_right"><input class="input" placeholder="请输入收货人姓名"></td>
            </tr>
            <tr>
                <td class="text-right">手机号码</td><td class="content_right"><input class="input" placeholder="请输入手机号码"></td>
            </tr>
            <tr>
                <td class="text-right">快递状态</td><td class="content_right"><input type="radio" name="status" value="1" class="status">已签收  <input name="status" type="radio" value="0" class="status">未签收</td>
            </tr>
            <tr>
                <td></td><td class="content_right"><span class="btn btn-info" id="update">立即修改</span> <span class="btn">重置</span> </td>
            </tr>
        </table>
    </div>
</div>
</body>
<script src="/qrcode/jquery2.1.4.js"></script>
<script src="/layer/layer.js"></script>
<script>
    $(".header:eq(1),.content:eq(1)").hide();//查询前，先隐藏展示查询结果的table
    var expressId=null; //定义全局变量:快递id，修改时需要使用
    var g_userPhone=null;//存放从数据库读取的收件人手机号，用于与修改后的手机号比较，判断是否修改了手机号
    $(function () {
        $("#find").click(function () { //绑定点击事件
            var windowId = layer.load();//加载的弹出层效果
            var number = $("#number").val();//获取输入表单的单号
            $.getJSON("/express/find.do",{number:number},function (data) {//发送ajax请求到服务器
                //{"status":0,"result":"查询成功","data":{"id":10,"number":"123123123","username":"李四","userPhone":"123456789","company":"顺丰快递","code":"819821","inTime":"Apr 2, 2021, 12:38:47 AM","status":0,"sysPhone":"123456789"}}
                layer.close(windowId);//关闭加载层
                layer.msg(data.result);//显示执行结果
                if (data.status==0){ //成功
                    $(".header:eq(1),.content:eq(1)").fadeIn(2000);//将展示查询结果的table淡入出来
                    expressId=data.data.id; //获取通过单号查询到的快件的id，过会根据id去更新
                    g_userPhone=data.data.userPhone;
                    $("input:eq(1)").val(data.data.number); //根据查询的快递填充到table表单中
                    $("input:eq(2)").val(data.data.company);
                    $("input:eq(3)").val(data.data.username);
                    $("input:eq(4)").val(data.data.userPhone);
                    if (data.data.status==0){
                        //未签收
                        $(".status:eq(1)").prop("checked",true);
                    }else {
                        //已签收
                        $(".status:eq(0)").prop("checked",true);
                    }
                }
            });
        });

        $("#update").click(function(){
            var windowId = layer.load();//加载效果
            var number = $("input:eq(1)").val();//先获取表单数据
            var company = $("input:eq(2)").val();
            var username = $("input:eq(3)").val();
            var userphone = $("input:eq(4)").val();

            var status = $(".status:checked").val();//获取单选框选中元素的值value,0:已签收 1:未签收
            var express = {   //将参数封装到对象发送到服务器
                id:expressId,
                number:number,
                company:company,
                username:username,
                status:status
            };
            if(userphone != g_userPhone){
                express.userphone = userphone;
            }else {
                userphone=null;
            }
            $.getJSON("/express/update.do",express,function(data){
                layer.close(windowId);
                layer.msg(data.result)

                if(data.status == 0){
                    //修改成功的，隐藏
                    $(".header:eq(1),.content:eq(1)").hide();
                }
            })
        });
    });
</script>
</html>
